import Http from '@/axios';

import { MenuForm, MenuQuery } from '@/model/sys/menu';

export default class MenuApi {
    public static insert(form: MenuForm) {
        return Http.post(this.handleUrl('insert'), form);
    }

    public static update(form: MenuForm) {
        return Http.post(this.handleUrl('update'), form);
    }

    public static delete(id: string) {
        return Http.post(this.handleUrl('delete'), { id });
    }

    public static pageList(query: MenuQuery) {
        return Http.get(this.handleUrl('list/page'), query);
    }

    public static info(id: string) {
        return Http.get(this.handleUrl('info'), { id });
    }

    public static list(query: MenuQuery) {
        return Http.get(this.handleUrl('list'), query);
    }

    public static dictList() {
        return Http.get(this.handleUrl('list/dict'));
    }

    public static currentList() {
        return Http.get(this.handleUrl('list/current'));
    }

    private static handleUrl(relativeUrl: string) {
        return `api/sys/menu/${relativeUrl}`;
    }
}
